package com.google.code.training_java_basic.basics;

import java.util.Arrays;
import java.util.Scanner;

/** Class Anagram receive input of two strings 
* and give the output to screen telling whether these words are anagrams*/

public class Anagram {

	public static void main(String[] args) {

    	Scanner scanner = new Scanner(System.in);
    	System.out.println("------------Anagram checker----------- ");
    	System.out.print("Enter the first String: ");
    	String firstWord = scanner.nextLine();
    	System.out.print("Enter the second String: ");
    	String secondWord = scanner.nextLine();
    	scanner.close();
		
		char[] charWord1 = firstWord.replaceAll(" ", "").toLowerCase().toCharArray();
		char[] charWord2 = secondWord.replaceAll(" ", "").toLowerCase().toCharArray();

		if(charWord1.length != charWord2.length){
				System.out.print("words/phrases are not anagrams, different length of words");
		}
		else {
		
			Arrays.sort(charWord1);
			Arrays.sort(charWord2);
		
			if(Arrays.equals(charWord1, charWord2)) {
				System.out.println("These words/phrases are anagrams");		
			} else {	
				System.out.print("words/phrases are not anagrams");
			}
		}
	}

}
